package us.gaaoc.framework.webapp.backingbeans;

import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.lowagie.text.pdf.PdfReader;

import us.gaaoc.framework.model.Documents;

@Component("documentBean")
@Scope("request")
@Transactional
public class DocumentBean extends BaseBackingBean
{

	private Documents document;
	private List<Page> pages;
	
	
	public DocumentBean() throws IOException {
		document = (Documents) this.getModelFacade().getSession().get(Documents.class,(Serializable) this.getSessionMap().get("documentUuid"));
		pages = new ArrayList<Page>();
		
		PdfReader reader = new PdfReader(document.getContent());
		int count = reader.getNumberOfPages();
		reader.close();
		for(int i = 1; i<=count;i++)
		{
			pages.add(new Page(i));
		}	
	}
	
	public List<Page> getPages() {
		return pages;
	}
	
	public Documents getDocument() {
		return document;
	}
	
	public void setDocument(Documents document) {
		this.document = document;
	}
	
	public void setPages(List<Page> pages) {
		this.pages = pages;
	}
	
	@javax.annotation.PreDestroy
	public void destroy() {}
}


